package com.apps.sworld;

import com.apps.sannotation.security.Authority;
import com.apps.smodule.Security.model.MethodPaths;
import com.apps.smodule.Security.utils.MethodPathUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface sController {

    /**
     * 获取接口的所有控制器路径
     * @return
     */
    default Map<String, MethodPaths> MethodPaths()
    {

        Map<String, MethodPaths> result=new HashMap<>();
        List<String> path=new ArrayList<>();
        RequestMapping requestMapping=this.getClass().getAnnotation(RequestMapping.class);
        if(requestMapping!=null)
        {
            for(int i=0;i<requestMapping.value().length;i++)
                path.add(requestMapping.value()[i]);
        }
        Method[] methods = this.getClass().getMethods();
        for(int i=0;i<methods.length;i++)
        {
            RequestMapping mapping = methods[i].getAnnotation(RequestMapping.class);
            if(null != mapping)
            {
                result.put(this.getClass().getSimpleName()+"_"+methods[i].getName(),new MethodPaths(mapping.name(), MethodPathUtils.CalculationPath(path,mapping.value())));
            }
        }
        return result;
    }
}
